<?php

namespace App\Models\Article;

use Illuminate\Database\Eloquent\Model;

/**
 *  文章模型层
 * Class Article
 * @package App\Models\Article
 */
class Article extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'article';

    /**
     * Indicates if the model should be timestamped.
     * @var bool
     */
    public $timestamps = false;

    public $appends = ['top_text', 'release_text', 'belong_to_text'];

    public $top            = [0 => '正常', 1 => '置顶'];
    public $release_status = [0 => '禁用', 1 => '启用'];
    public $belong_to      = [0 => '全部显示', 1 => 'App', 2 => 'PC'];

    // 置顶状态修改器
    public function getTopTextAttribute()
    {
        return $this->top[$this['top']];
    }

    // 启用状态修改器
    public function getReleaseTextAttribute()
    {
        return $this->release_status[$this['release_status']];
    }

    // 启用状态修改器
    public function getBelongToTextAttribute()
    {
        return $this->belong_to[$this['belong_to']];
    }

    // 关联文章主题
    public function articleClassify()
    {
        return $this->belongsTo(ArticleClassify::class,'classify_id', 'id');
    }

}
